<template>
  <div class="grid-content">
    <!-- 显示当前出发地和目的地 -->
    <span class="picker">
      <el-select filterable  v-model="citys.start_city" placeholder="出发地">
        <el-option v-for="item of options" :key="item" :label="item" :value="item"></el-option>
      </el-select>
    </span>
    <span id="arrow">
      <img src="../assets/arrow-right.png" height="25px">
    </span>
    <span class="picker">
      <el-select filterable  v-model="citys.arrive_city" placeholder="到达地">
        <el-option v-for="item of options" :key="item" :label="item" :value="item"></el-option>
      </el-select>
    </span>
    <span id="search-btn">
      <el-button type="primary" @click="onClickSearch" icon="el-icon-search">搜 索</el-button>
    </span>
  </div>
</template>

<script>
import axios from "axios";
import CityPicker from "./CityPicker.vue";
export default {
  components: { CityPicker },
  name: "CitySearcher",
  data() {
    return {
      options: [],
      citys: {
        start_city: "",
        arrive_city: ""
      }
    };
  },
  methods: {
    getData() {
      axios
        .get(this.$GLOBAL.localHost + "gcity/")
        .then(response => {
          console.log(response)
          this.options = response.data.root[0];
        })
        .catch(error => console.log(error));
    },
    onChangeStartCity(val) {
      this.citys.start_city = val;
    },
    onChangeArriveCity(val) {
      this.citys.arrive_city = val;
    },
    onClickSearch() {
      this.$emit("search-city", this.citys);
    }
  },
  created() {
    this.getData();
  }
};
</script>

<style scoped>
#arrow {
  padding: 5px;
}
#search-btn{
  margin: 0 10px;
}
.picker{
  margin: 0 10px;
}
.grid-content {
  display: flex;
  justify-content: space-between;
  align-content: center;
  border-radius: 4px;
  min-height: 36px;
}
</style>